#!/usr/bin/env bash
set -e

cd $(dirname $0)
pwd

# download cli jar tool from
# http://maven.aliyun.com/nexus/content/groups/public/io/swagger/swagger-codegen-cli/2.2.3/swagger-codegen-cli-2.2.3.jar

gen_target=$(pwd)/.api
target_dir=$(pwd)/../src/api

if [[ ! -d "${target_dir}" ]]; then
  mkdir -p ${target_dir}
fi
mkdir -p ${gen_target}

java -jar ~/bin/swagger-codegen-cli.jar  \
    generate \
    -l javascript \
    -c config.json \
    -i http://127.0.0.1:9910/meiju-boss/api/v2/api-docs \
    --type-mappings Date=Number \
    --type-mappings LocalDate=Number \
    -o ${gen_target}

cp -r ${gen_target}/src/* ${target_dir}
cp -r ${gen_target}/docs ${target_dir}

rm -rf ${gen_target}
echo "Done!"
